from appium import webdriver

from weekend.wework.base.base_page import BasePage


class WeWorkPage(BasePage):

    def start(self):
        caps = {}
        caps["platformName"] = "android"
        caps["platformVersion"] = "6.0"
        caps["appium:deviceName"] = "wework"
        caps["appium:appActivity"] = ".launch.LaunchSplashActivity"
        # 不清除应用数据，不卸载app
        caps["appium:noReset"] = "true"
        caps["appium:appPackage"] = "com.tencent.wework"
        # 不重启app
        caps["appium:dontStopAppOnReset"] = "true"
        caps["appium:ensureWebviewsHavePages"] = True
        caps["appium:nativeWebScreenshot"] = True
        caps["appium:newCommandTimeout"] = 3600
        caps["appium:connectHardwareKeyboard"] = True
        # client 与server 端建立连接
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
        self.driver.implicitly_wait(10)
        return self

    def restart(self):
        """
        重启app，先关闭，在激活
        :return:
        """
        self.driver.close()
        self.driver.activate_app('com.tencent.wework')
        return self

    def stop(self):
        self.driver.quit()

    def goto_main_page(self):
        from weekend.wework.page.main import MainPage
        return MainPage(self.driver)
